package com.spddr.pmos.jpa;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embeddable;

import org.joda.time.Period;

@Embeddable
public class ObjectDataStorageId implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	private int objectType;
	private String metric;
	private Period interval;

	public ObjectDataStorageId() {
	}

	public ObjectDataStorageId(int objectType, String metric, Period interval) {
		this.objectType = objectType;
		this.metric = metric;
		this.interval = interval;
	}

	@Column(name = "object_type", nullable = false)
	public int getObjectType() {
		return objectType;
	}

	public void setObjectType(int objectType) {
		this.objectType = objectType;
	}

	@Column(name = "metric", nullable = false)
	public String getMetric() {
		return metric;
	}

	public void setMetric(String metric) {
		this.metric = metric;
	}

	@Column(name = "interval", nullable = false)
	@Convert(converter = cn.seqdata.jpa.converter.PeriodConverter.class)
	public Period getInterval() {
		return this.interval;
	}

	public void setInterval(Period interval) {
		this.interval = interval;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((interval == null) ? 0 : interval.hashCode());
		result = prime * result + ((metric == null) ? 0 : metric.hashCode());
		result = prime * result + objectType;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ObjectDataStorageId other = (ObjectDataStorageId) obj;
		if (interval == null) {
			if (other.interval != null)
				return false;
		} else if (!interval.equals(other.interval))
			return false;
		if (metric == null) {
			if (other.metric != null)
				return false;
		} else if (!metric.equals(other.metric))
			return false;
		if (objectType != other.objectType)
			return false;
		return true;
	}
}
